﻿using System;
using System.Collections.Generic;
using Landpy.LogAnalyzer.Configuration;

namespace Landpy.LogAnalyzer.Log
{
    public class LogRow
    {
        private readonly Dictionary<string, string> columValues;

        public LogRow()
        {
            columValues = new Dictionary<string, string>();
        }

        public string this[string key]
        {
            get
            {
                string returnValue = String.Empty;
                if (columValues != null)
                {
                    if (columValues.ContainsKey(key))
                    {
                        returnValue = columValues[key];
                    }
                    else
                    {
                        // N/A.
                    }
                }
                else
                {
                    // N/A.
                }
                return returnValue;
            }
            set
            {
                if (columValues.ContainsKey(key))
                {
                    columValues[key] = value;
                }
                else
                {
                    columValues.Add(key, value);
                }
            }
        }

        public override bool Equals(object obj)
        {
            bool isEquals = false;
            if (obj != null)
            {
                var logRow = obj as LogRow;
                if (logRow != null)
                {
                    isEquals = true;
                    foreach (LogColumn logColumn in ConfigurationSession.GetSession().Setting.Columns)
                    {
                        if (logColumn.Filter.Contains("Time"))
                        {
                            // N/A.
                        }
                        else
                        {
                            if (logRow[logColumn.HeaderText] != this[logColumn.HeaderText])
                            {
                                isEquals = false;
                                break;
                            }
                            else
                            {
                                // N/A.
                            }
                        }
                    }
                }
            }
            return isEquals;
        }
    }
}